\documentclass[10pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}	
\usepackage{graphicx}
\setcounter{secnumdepth}{3}
\usepackage[margin=3cm]{geometry}
\date{}
\author{}
\title{Spørgsmål 7}
\subtitle{SQL herunder DML og DDL, samt strukturen for og mulighederne med SQL erklæringer}

\begin{document}
\maketitle

\section{DDL - Data Definition Language}
Used to create, modify and remove the structure of database objects in database.

\subsection{Create syntax}
CREATE [TEMPORARY] TABLE \textit{[table name]} ( \textit{[column definitions]} ) \textit{[table parameters]}

\subsubsection{Column definition syntax}
Column definition: \textit{[column name] [data type] \{NULL $|$ NOT NULL\} \{column options\}}
\begin{center}
\includegraphics[scale=1]{spg7-1.jpg}
\end{center}

\subsection{Drop syntax}
DROP \textit{objecttype objectname}
\begin{center}
\includegraphics[scale=1]{spg7-2.jpg}
\end{center}

\subsection{Alter syntax}
ALTER \textit{objecttype objectname parameters}
\begin{center}
\includegraphics[scale=1]{spg7-3.jpg}
\end{center}

\newpage
\section{DML - Data Manipulation Language}
Used to retrieve, store, modify, delete, insert and update data in database.

\subsection{Select syntax}
\textbf{WHERE} \textit{specifies which rows to retrieve.} \\
\textbf{GROUP BY} \textit{groups rows sharing a property so that an aggregate function can be applied to each group.} \\
\textbf{HAVING} \textit{selects among the groups defined by the GROUP BY clause.} \\
\textbf{ORDER BY} \textit{specifies an order in which to return the rows.}

\subsubsection{Join Syntax}
Join data from two or more tables.\\
\noindent
\textbf{(INNER) JOIN} \textit{Return rows where there are at least one match in both tables}\\
\textbf{LEFT JOIN} \textit{Return all rows from the table on the left side of the join statement, even if there are no matches in the right table}\\
\textbf{RIGHT JOIN} \textit{Return all rows from the table on the right side of the join statement, even if there are no matches in the left table}\\
\textbf{FULL JOIN} \textit{Return rows where there is a match in either table}\\

\noindent
\textbf{Select Statment Example:}
\noindent
\textbf{SELECT} table1.ID, table2.column
\textbf{FROM} table1
\textbf{LEFT JOIN} table2
\textbf{ON} table1.ID=table2.ID
\textbf{WHERE} isActive = 1\\

\noindent
The above statment returns data from the column "ID" in table1 and "column in table2, it will always return data even if there are no matches in the right table (if there is no data in table2.column). The two tables are joined on the primary key "ID".

\subsection{Update syntax}
UPDATE \textit{table\_name} SET \texxtit{column\_name} = \textit{value} [, \textit{column\_name} = \textit{value} ...] [WHERE \textit{condition}]
\begin{center}
\includegraphics[scale=1]{spg7-5.jpg}
\end{center}


\subsection{Insert syntax}
INSERT INTO \textit{table} (\textit{column1} [, \textit{column2}, \textit{column3} ... ]) VALUES (\textit{value1} [, \textit{value2}, \textit{value3} ... ])
\begin{center}
\includegraphics[scale=1]{spg7-6.jpg}
\end{center}



\subsection{Delete syntax}
DELETE FROM \textit{table\_name} [WHERE \textit{condition}]
\begin{center}
\includegraphics[scale=1]{spg7-7.jpg}
\end{center}



\end{document}